﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Pibby.Core.IO.Tests
{
	[TestClass]
	public class FileNameSanitizerTests
	{
		[TestMethod]
		public void FileNameSanitizer_CanFix_InvalidFileName()
		{
			string alistName = "A List Apart: for people who make websites";
			string expectedName = "A List Apart for people who make websites";

			string fixedName = FileNameSanitizer.FixFileName(alistName);

			Assert.AreEqual(expectedName, fixedName);
		}

		[TestMethod]
		public void FilenameSanitizer_CanRemove_SpacesFromName()
		{
			string alistName = "A List Apart: for people who make websites";
			string expectedName = "AListApartforpeoplewhomakewebsites";

			string fixedName = FileNameSanitizer.ScrubSpaces(alistName);

			Assert.AreEqual(expectedName, fixedName);
		}

		[TestMethod]
		public void FileNameSanitizer_CanFix_WebLink_WithQuestionAfter()
		{
			string mikeBennetImage = "Image200.jpg?abcdefg";

			string fixedName = FileNameSanitizer.FixWebLink(mikeBennetImage);

			Assert.AreEqual("Image200.jpg", fixedName);
		}

		[TestMethod]
		public void FileNameSanitizer_CanFix_WebLink_WithQueryAtStart()
		{
			string queryString = "?feed=podcast";

			string fixedName = FileNameSanitizer.FixWebLink(queryString);

			Assert.AreEqual("podcast", fixedName);
		}


		[TestMethod]
		public void FileNameSanitizer_DoesNotChange_WebLink_WithoutQuestionAfter()
		{
			string mikeBennetImage = "Image200.jpeg";

			string fixedName = FileNameSanitizer.FixWebLink(mikeBennetImage);

			Assert.AreEqual(mikeBennetImage, fixedName);
		}

		[TestMethod]
		public void FileNameSanitizer_Should_Remove_DoubleSpaces()
		{
			string withColonAndSpace = "This has a colon: and some spaces";

			string fixedName = FileNameSanitizer.FixFileName(withColonAndSpace);

			Assert.AreEqual("This has a colon and some spaces", fixedName);
		}


		[TestMethod]
		public void FileNameSanitizer_CanCamelCase_SpacedLowerCaseName()
		{
			string spacedName = "this is a lower case name";
			string expected = "This Is A Lower Case Name";

			string result = FileNameSanitizer.CamelCaseName(spacedName);

			Assert.AreEqual(expected, result, "Camel case does not work");
		}

		[TestMethod]
		public void FileNameSanitizer_CanCamelCase_SpacedMixedCaseName()
		{
			string mixedName = "This is A mixed Case name";
			string expected = "This Is A Mixed Case Name";

			string result = FileNameSanitizer.CamelCaseName(mixedName);

			Assert.AreEqual(expected, result, "Camel case does not work");
		}

		[TestMethod]
		[ExpectedException (typeof(ArgumentNullException))]
		public void FileNameSanitizer_CannotCamelCase_EmptyString()
		{
			FileNameSanitizer.CamelCaseName(string.Empty);

			Assert.Fail("Should not get here");
		}

	}
}
